<template>
    <div class="AppMain">
        <div class="select-theme">
            <el-select v-model="value" placeholder="Select" style="width: 240px" @change="handleMenuClick">
                <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
        </div>

        <div class="mb-4">
            <el-button>Default</el-button>
            <el-button type="primary">Primary</el-button>
            <el-button type="success">Success</el-button>
            <el-button type="info">Info</el-button>
            <el-button type="warning">Warning</el-button>
            <el-button type="danger">Danger</el-button>
        </div>

        <div class="mb-4">
            <el-button plain>Plain</el-button>
            <el-button type="primary" plain>Primary</el-button>
            <el-button type="success" plain>Success</el-button>
            <el-button type="info" plain>Info</el-button>
            <el-button type="warning" plain>Warning</el-button>
            <el-button type="danger" plain>Danger</el-button>
        </div>

        <div class="mb-4">
            <el-button round>Round</el-button>
            <el-button type="primary" round>Primary</el-button>
            <el-button type="success" round>Success</el-button>
            <el-button type="info" round>Info</el-button>
            <el-button type="warning" round>Warning</el-button>
            <el-button type="danger" round>Danger</el-button>
        </div>

        <div>
            <el-button :icon="Search" circle />
            <el-button type="primary" :icon="Edit" circle />
            <el-button type="success" :icon="Check" circle />
            <el-button type="info" :icon="Message" circle />
            <el-button type="warning" :icon="Star" circle />
            <el-button type="danger" :icon="Delete" circle />
        </div>

        <div style="font-size: 20px">
            <!-- 由于SVG图标默认不携带任何属性 -->
            <!-- 你需要直接提供它们 -->
            <Edit style="width: 1em; height: 1em; margin-right: 8px" />
            <Share style="width: 1em; height: 1em; margin-right: 8px" />
            <Delete style="width: 1em; height: 1em; margin-right: 8px" />
            <Search style="width: 1em; height: 1em; margin-right: 8px" />
        </div>
    </div>
</template>

<script>
import { Check, Delete, Edit, Message, Search, Star } from "@element-plus/icons-vue";
import { setTheme } from "./css/theme.js";
import { onMounted, defineComponent, ref } from "vue";

export default defineComponent({
    name: "App",
    computed: {
        Edit() {
            return Edit;
        },
        Search() {
            return Edit;
        },
        Check() {
            return Check;
        },
        Message() {
            return Message;
        },
        Star() {
            return Star;
        },
        Delete() {
            return Delete;
        },
    },
    components: {
        Check,
        Delete,
        Edit,
        Message,
        Search,
        Star,
    },
    setup() {
        const value = ref("");
        const options = ref([
            {
                value: "theme0",
                label: "默认主题",
            },
            {
                value: "theme1",
                label: "紫色主题",
            },
        ]);
        // 主题切换函数
        const handleMenuClick = async (e) => {
            setTheme(value.value);
            localStorage.setItem("theme", value.value);
        };
        onMounted(() => {
            // 主题本地存储持久化
            const theme = localStorage.getItem("theme") || "theme0";
            if (theme) {
                setTheme(theme);
            }
        });
        return {
            value,
            options,
            handleMenuClick,
        };
    },
});
</script>
<style lang="less" scoped>
.AppMain {
    width: 100vw;
    height: 100vh;
    background: @bodyimg;
    background-repeat: no-repeat;
    background-size: cover;
    .select-theme {
        position: fixed;
        left: 50px;
        top: 50px;
    }
}
</style>
